/* eslint-disable vue/html-indent */ /* eslint-disable vue/html-indent */
<template>
  <div class="cs-page-container">
    <div class="cs-filter-container">
      <el-select
        v-model="listQuery.msgType"
        clearable
        placeholder="聊天类型"
      >
        <el-option label="免费聊天女用户回复率" :value="1" />
        <el-option label="收费聊天女用户回复率" :value="2" />
        <el-option label="免费聊天男用户回复率" :value="3" />
        <el-option label="收费聊天男用户回复率" :value="4" />
      </el-select>
      <el-date-picker
        v-model="daterangeValue"
        :picker-options="daterangePickerOptions"
        type="daterange"
        align="right"
        unlink-panels
        range-separator="至"
        start-placeholder="起始时间"
        end-placeholder="结束时间"
        value-format="yyyy-MM-dd"
        clearable
        @change="daterangeChangedTimestamp"
      />
      <el-button
        type="primary"
        icon="el-icon-search"
        :loading="listLoading"
        @click="handleFilter"
      >
        查询
      </el-button>
      <el-button
        type="info"
        size="small"
        icon="el-icon-refresh-right"
        @click="resetFilter"
      >
        重置
      </el-button>
    </div>
    <div class="cs-filter-result">
      <el-table
        v-loading="listLoading"
        :data="list"
        border
        fit
        size="small"
        highlight-current-row
        element-loading-text="拼命加载中"
        element-loading-spinner="el-icon-loading"
        :height="'calc(100vh - 250px)'"
      >
        <el-table-column align="center" label="日期">
          <template slot-scope="{ row }">
            <span>{{
              (row.sendTime) | parseTime('{y}-{m}-{d}')
            }}</span>
          </template>
        </el-table-column>

        <el-table-column align="center" label="付费">
          <template slot-scope="{ row }">
            <span>{{
              pay_status[row.fromGender][row.pay]
            }}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="聊天总数" prop="imMsgCount">
        </el-table-column>
        <el-table-column align="center" label="5分钟">
          <template slot-scope="{ row }">
            <span>{{ ((row.fiveMinutes / row.imMsgCount) * 100).toFixed(2) }}%({{ (row.fiveMinutes) }})</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="15分钟">
          <template slot-scope="{ row }">
            <span>{{ (((row.fifteenMinutes - row.fiveMinutes) / row.imMsgCount) * 100).toFixed(2) }}%({{ (row.fifteenMinutes - row.fiveMinutes) }})</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="30分钟">
          <template slot-scope="{ row }">
            <span>{{ (((row.halfHour - row.fifteenMinutes) / row.imMsgCount) * 100).toFixed(2) }}%({{ (row.halfHour - row.fifteenMinutes) }})</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="60分钟">
          <template slot-scope="{ row }">
            <span>{{ (((row.oneHour - row.halfHour) / row.imMsgCount) * 100).toFixed(2) }}%({{ (row.oneHour - row.halfHour) }})</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="120分钟">
          <template slot-scope="{ row }">
            <span>{{ (((row.towHour - row.oneHour) / row.imMsgCount) * 100).toFixed(2) }}%({{ (row.towHour - row.oneHour) }})</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="120分钟以上">
          <template slot-scope="{ row }">
            <span>{{ (((row.imMsgCount - row.towHour) / row.imMsgCount) * 100).toFixed(2) }}%({{ (row.imMsgCount - row.towHour) }})</span>
          </template>
        </el-table-column>
      </el-table>
      <TablePagination
        :current-page="listQuery.page"
        :limit="listQuery.limit"
        :total="total"
        :loading="listLoading"
        @handleSizeChange="handleSizeChange"
        @handleCurrentChange="handleCurrentChangeOffset"
      />
    </div>
  </div>
</template>

<script>
  import TablePagination from '@/components/TablePagination'
  import DATEPICKER_OPTIONS from '@/config/datepickerOptions'
  import { xhrImMsgReversionRate } from '@/api/analysis'

  export default {
    name: 'ImMsgAnalysis',
    components: { TablePagination },
    data() {
      return {
        list: [],
        total: 0,
        listQuery: {
          offset: 0,
          limit: 100,
          msgType: null,
          startTime: null,
          endTime: null
        },
        pay_status: {
          1: { 0: '免费聊天女用户回复率', 1: '收费聊天女用户回复率' },
          2: { 0: '免费聊天男用户回复率', 1: '收费聊天男用户回复率' }
        },
        daterangeValue: '',
        daterangePickerOptions: DATEPICKER_OPTIONS.daterangePickerOptions
      }
    },
    created() {
      this.doSearch()
    },
    methods: {
      doSearch() {
        xhrImMsgReversionRate(this.listQuery).then(resp => {
          this.listLoading = false
          this.total = resp.data.count
          this.list = resp.data.list
        }).catch(res => {
          this.listLoading = false
          this.$message.error(res)
        })
      }
    }
  }
</script>
